﻿using System;

namespace BDSA12 {

    class Program {

        static bool IsPowerOf(int a, int b) {
            //special case if b==2 - we use the bitwise operator & and may save potential computations
            if (b == 2)
                return (a & (a-1)) == 0;
            //otherwise we use the recursive form
            else if (a == b || (a % b == 0 && IsPowerOf((a / b), b)))
                return true;
            else
                return false;
        }

        static void Main(string[] args) {
            if (args.Length == 2) {
                try {
                    Console.WriteLine("Is "+args[0]+" a power of "+args[1]+" ?\n");
                    Console.WriteLine(IsPowerOf(int.Parse(args[0]), int.Parse(args[1])));
                    Console.ReadKey();
                }
                catch (Exception e) {
                    Console.WriteLine(e);
                    Console.ReadKey();
                }
            }
        }
    }
}
